package com.kylin.module.services.business;

import java.util.Date;

import org.apache.log4j.Logger;

import com.kylin.common.dict.orm.Dict;
import com.kylin.common.exception.BusinessException;
import com.kylin.common.paginate.DisplayPage;
import com.kylin.common.paginate.PageManager;
import com.kylin.hibernate.BaseHibernateDAO;
import com.kylin.hibernate.CriteriaInfo;
import com.kylin.module.services.forms.ServiceForm;
import com.kylin.module.services.orm.Service;

/**
 * 业务逻辑类：服务模块
 * @author duhui
 *
 */
public class ServiceBlogic {

	private int pageSize = 5;

	protected static Logger log = Logger.getLogger(ServiceBlogic.class);

	public void addService(ServiceForm form) throws BusinessException {
		log.debug("插入新的服务内容 ：" + form.getContent());
		Service obj = new Service();
		// try {
		// BeanUtils.copyProperties(obj, form);
		// } catch (IllegalAccessException e) {
		// // TODO 自动生成 catch 块
		// e.printStackTrace();
		// } catch (InvocationTargetException e) {
		// // TODO 自动生成 catch 块
		// e.printStackTrace();
		// }
		obj.setAddress(form.getAddress());
		obj.setContact(form.getContact());
		obj.setContent(form.getContent());
		obj.setCity(form.getCity());
		obj.setCatService(new Dict(form.getCatService()));
		obj.setCountry(form.getCountry());
		obj.setPosition(new Dict(form.getPosition()));
		obj.setEmail(form.getEmail());
		obj.setFax(form.getFax());
		obj.setFaxArea(form.getFaxArea());
		obj.setFaxCountry(form.getFaxCountry());
		obj.setPhone(form.getPhone());
		obj.setPhoneArea(form.getPhoneArea());
		obj.setPhoneCountry(form.getPhoneCountry());
		obj.setPostcode(form.getPostcode());
		
		obj.setCreatedon(new Date());
		obj.setLanguage(form.getLanguage());
		BaseHibernateDAO.save(obj);
	}

	public Service getServiceById(Long id) throws BusinessException {
		return (Service) BaseHibernateDAO.findById(Service.class, id);
	}

	public void deleteServiceById(Long id) throws BusinessException {
		Service service = getServiceById(id);
		if (service != null) {
			BaseHibernateDAO.deleteById(Service.class, id);
		}

	}
}
